#pragma once

#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <cerrno>
#include <strings.h>
#include <cstdlib>
#include <functional>

#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

using namespace std;

#define Die(code)   \
    do              \
    {               \
        exit(code); \
    } while (0)                        // 为了代码好看？？
#define CONV(v) (struct sockaddr *)(v) // 强转

enum
{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR
};

bool SplitString(const string& line, string* key, string* value, const string& sep)
{
    int pos = line.find(sep);
    if(pos == string::npos) return false;  // 没找到分隔符，说明不对
    *key = string(line.begin(), line.begin()+pos);
    *value = string(line.begin() + pos + sep.size(), line.end());
    if(key->empty() || value->empty())
        return false;
    return true;
}